#!/usr/bin/env ruby

require 'mysql'
require 'date'

class CustomerFinder
    def initialize(connection)
        @connection = connection;
    end
    
    def find(date)
        sql = "select name, email, number, keyword, provision_date, expiration_date from customers
        where expiration_date < '#{date}' and enabled=true"
        puts sql
        result = @connection.query(sql)
        result
    end
end

connection = Mysql.new('localhost', 'ag3nt', 'password', 'smsclient')
customerfinder = CustomerFinder.new(connection)
resultset = customerfinder.find(Date::today() + 10)

email = []
resultset.each_hash { |h| email.push(sprintf("%s, %s, %s, %s\n", h['name'], h['email'], h['provision_date'], h['expiration_date'])) }
print email

connection.close